package com.example.carconsumer.controller.rsh;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.carinterface.pojo.User;
import com.example.carinterface.service.rsh.InsuranceService;
import com.example.carinterface.service.rsh.InsuranceTypeService;
import com.example.carinterface.utils.ResultJson;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static org.apache.shiro.web.filter.mgt.DefaultFilter.user;


@Api(value = "保险模块",tags = "保险数据接口API")
@RestController
@RequestMapping("/user")
@CrossOrigin
public class InsuranceController {

    @Reference(check = false)
    private InsuranceService insuranceService;
    ResultJson resultJson = new ResultJson();
    @Reference
    private InsuranceTypeService insuranceTypeService;

    /**
     * 添加保险
     *
     * @param map
     * @return
     */
    @RequestMapping(value = "/addInsurance", method = RequestMethod.POST)
    @ApiOperation(value = "添加保险接口",notes = "车主卡已经存在，才添加保单信息", httpMethod = "post",response = ResultJson.class)
    public Map<String, Object> addInsurance(@ApiParam(name = "map",value = ""+
    "ownerCard_id:车主卡id\t\t"+
            "creatTime:下单时间\t\t"+
            "Insurance_policyNo:交强险保单号\t\t"+
            "businessInsurance_policyNo:商业险保单号\t\t"+
            "state:'订单状态:1、车辆信息待审核\t\t" +
            "2、待录入信息；3、待录入保费；4、待付款；" +
            "5、待录入验证码；6、已完成',"+
            "idCardImg:身份证照片\t\t"+
            "insuranceOrder_word:保险单word文档地址\t\t"+
            "actualTotalPrice:实际总价\t\t"+
            "policyNoStartTime:交强保单起始时间\t\t"+
            "policyNoDeadTime:交强保单终止时间\t\t"+
            "businessNoStartTime:商业险保单起始时间\t\t"+
            "businessNoDeadTime:商业险保单终止时间\t\t",required = true)@RequestBody Map<String, Object> map) {
        Boolean aboolean = insuranceService.insertInsurance(map);
        if (aboolean) {
            resultJson.setMsg("添加成功");
            resultJson.setCode("200");
        } else {
            resultJson.setMsg("添加失败");
            resultJson.setCode("500");
        }
        return map;
    }

    /**
     * 查询保险类型与保费信息
     *
     * @return
     */
    @RequestMapping(value = "/selectInsranceType", method = RequestMethod.GET)
    @ApiOperation(value = "查询保险类型与保费信息",httpMethod = "get",response = ResultJson.class)
    public ResultJson getInsuranceTypeInfo() {
        ResultJson InsuranceType = insuranceTypeService.getInsuranceTypeInfo();
        System.out.println(InsuranceType);
        return InsuranceType;
    }

    /**
     * 根据车主卡id查询车主卡信息
     * @param map
     * @return
     */
    @RequestMapping(value = "/selectOwnerInfor", method = RequestMethod.POST)
    @ApiOperation(value = "查询车主卡信息",notes = "根据车主卡id查询",httpMethod = "post",response = ResultJson.class)
    public ResultJson selectOwnerById(@ApiParam(name = "map",value = ""+
    "id:车主卡id",required = true)@RequestBody Map<String, String> map) {
        return insuranceService.selectOwerCardById(Integer.parseInt(map.get("id")));
    }


    /**
     * 根据user的id查询保险订单
     * @param user
     * @return
     */
    @RequestMapping(value = "/selectInsuranceOrder", method = RequestMethod.POST)
    @ApiOperation(value = "查询保险订单",notes = "根据user的id查询",httpMethod = "post",response = ResultJson.class)
    public ResultJson selectInsuranceOrder(@ApiParam(name = "map",value = ""+
    "id:user的id",required = true)@RequestBody User user){
        return insuranceService.selectInsuranceOrder(user);
    }

    /**
     * 核对车辆信息
     * @return
     */
    @RequestMapping(value = "/selectCarInfo", method = RequestMethod.GET)
    @ApiOperation(value = "查询核对车辆信息",httpMethod = "get",response = ResultJson.class)
    public ResultJson checkCarInfo(){
        ResultJson carInfo = insuranceService.checkCarInfo();
        System.out.println(carInfo);
        return carInfo;
    }

    /**
     * 获取报价信息
     * @return
     */
    @RequestMapping(value = "/selectOfferInfo", method = RequestMethod.GET)
    @ApiOperation(value = "查询保险各段位的保险价格",httpMethod = "get",response = ResultJson.class)
    public ResultJson selectOfferInfo(){
        ResultJson offerInfo = insuranceService.selectOfferInfo();
        System.out.println(offerInfo);
        return offerInfo;
    }

    /**
     * 获取录入信息
     * @return
     */
    @RequestMapping(value = "/selectInputInfo", method = RequestMethod.GET)
    @ApiOperation(value = "查询保险订单状态中的录入信息",notes = "",httpMethod = "get",response = ResultJson.class)
    public ResultJson getInputInfo(){
        ResultJson InputInfo = insuranceService.getInputInfo();
        System.out.println(InputInfo);
        return InputInfo;
    }

    @RequestMapping(value = "/selectStopTime", method = RequestMethod.POST)
    @ApiOperation(value = "用于查询保险的有效日期接口",notes = "输入车牌号码查询",httpMethod = "post",response = ResultJson.class)
    public  ResultJson getStopTime(@ApiParam (name = "map" ,value = "" +
            "license_Plate_Number:车牌号，",required = true)  @RequestBody Map<String , Object> map){
        System.out.println(map);
        ResultJson stopTime = insuranceService.getStopTime((String) map.get("license_Plate_Number"));
        return  stopTime;
    }

    /**
     * 根据user查询保险理赔
     * @param user
     * @return
     */
    @RequestMapping(value = "/selectInsuranceClaims", method = RequestMethod.POST)
    @ApiOperation(value = "用于查询用户保险理赔信息接口",notes = "",httpMethod = "post",response = ResultJson.class)
    public ResultJson getInsuranceClaims(@ApiParam(name = "user",value = ""+
    "id：user的id",required = true)@RequestBody User user){
        return insuranceService.getInsuranceClaims(user);

    }

    /**
     * 添加保险理赔详情
     * @param map
     * @return
     */
    @RequestMapping(value = "/addALLInsuranceClaims", method = RequestMethod.POST)
    @ApiOperation(value = "用于添加保险理赔详情接口",notes = "",httpMethod = "post",response = ResultJson.class)
    public ResultJson addALLInsuranceClaims(@ApiParam(name = "map",value = ""+
    "site:地点\t\t"+
            "time:时间\t\t"+
            "accidentType:事故类型\t\t"+
            "locationCoordinates:地点坐标\t\t"+
            "ownerCardId:车主卡id\t\t"+
            "tel:联系电话\t\t"+
            "state:申请状态：1、未审核；2、审核不通过（照片不清晰）；3、审核通过\t\t"+
            "list:理赔车辆损坏照片及价格编号list数组\t\t"+
            "carPartsPriceId：理赔车辆损坏部件价格编号\t\t"+
            "damageImg:损坏照片\t\t",required = true)@RequestBody Map<String, Object> map) {
        System.out.println("========control========");
        return insuranceService.insertALLInsuranceClaims(map);
    }


}